package checker

import (
	"kumachan/interpreter/lang/ast"
	"kumachan/interpreter/lang/common/source"
	"kumachan/interpreter/compiler/checker/typsys"
	"kumachan/interpreter/compiler/checker/checked"
)


type checkContext struct {
	location     source.Location
	expected     typsys.Type
	inferring    *typsys.InferringState
	exprContext  ExprContext
}
func makeCheckContext (
	loc  source.Location,
	exp  typsys.Type, // nullable
	s    *typsys.InferringState,
	ctx  ExprContext,
) *checkContext {
	return &checkContext {
		location:    loc,
		expected:    exp,
		inferring:   s,
		exprContext: ctx,
	}
}
func (cc *checkContext) copy() *checkContext {
	var copy_ = *cc
	return &(copy_)
}

type checkContextWithLocalScope struct {
	*checkContext
}
func makeCheckContextWithLocalScope (
	loc  source.Location,
	exp  typsys.Type, // nullable
	s    *typsys.InferringState,
	ctx  ExprContext,
) *checkContextWithLocalScope {
	var cc = makeCheckContext(loc, exp, s, ctx)
	cc.exprContext = cc.exprContext.withNewLocalScope()
	return &checkContextWithLocalScope { checkContext: cc }
}
func (cc *checkContextWithLocalScope) productPatternMatch(pattern ast.VariousPattern, in typsys.Type) (checked.ProductPatternInfo, *source.Error) {
	var mod = cc.exprContext.ModName
	var lm = cc.exprContext.LocalBindingMap
	return productPatternMatch(pattern)(in, mod, lm)
}
func (cc *checkContextWithLocalScope) injectLocalBinding(b *checked.LocalBinding) {
	var lm = cc.exprContext.LocalBindingMap
	lm.add(b)
}


